home *** CD-ROM | disk | FTP | other *** search
- Path: tank.news.pipex.net!pipex!iol!usenet
- From: David Byrden <goyra@iol.ie>
- Newsgroups: comp.lang.c++
- Subject: Re: Implicit Typecasting
- Date: 16 Mar 1996 21:44:51 GMT
- Organization: Ireland On-Line
- Message-ID: <4ifcoj$m8o@nuacht.iol.ie>
- References: <1996Mar16.203628.15187@mcs.drexel.edu>
- NNTP-Posting-Host: dialup-184.dublin.iol.ie
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.22KIT (Windows; I; 16bit)
-
-
- ucphinni@mcs.drexel.edu (C. K. Phinnizee) wrote:
-
- >class llNode {
- > typedef llNode ll;
- > public:
- > llNode(ll * anext = NULL) { nextptr = anext;}
- > ll * next(void) { return nextptr;}
- > ll * next(ll * anext) { return nextptr = anext;}
- > ... cut code ...
- > private:
- > ll * nextptr;
- >};
-
-
- >class dlNode : public llNode {
- > typedef dlNode dl;
- > public:
- > dlNode(dl * aprev = NULL,dl * anext = NULL)
- > : ll((ll *) anext)
-
-
- The cast from dl to ll is not necessary! C++ will cast it implicitly
- because ll is a base of dl.
-
-
-
-
- > dl * prev(void) { return (dl *) prevptr.next();}
-
- Can't avoid this cast.
-
-
- > dl * prev(dl * aprev)
- > {
- > return (dl *) prevptr.next((dl *) aprev);
- > }
-
-
- Why cast aprev? It is already a dl*
-
-
- To sum up; you need only perform the casts from ll to dl. They are
- necessary because only YOU know that a particular ll is really a dl. These
- casts will have no runtime cost, so things are not too bad.
-
-
- David
-
-
-